from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup

specifiedurl = "http://www.pythonscraping.com/pages/page1.html"

# define the url files open common use function
def getTitle(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        return None
    try:
        # create a bs object
        bsObj = BeautifulSoup(html, "lxml")
        title = bsObj.body.h1
    except AttributeError as e:
        return None
    return title

def isNotNull(object):
    if object == None:
        print("object could not be found!")
    else:
        return object

def main():

    htmlContent = getTitle(specifiedurl)
    print(isNotNull(htmlContent))

if __name__ == '__main__':
    main()
